import MyRequest from '@/utils/request/index'

class Order {
  createOrder = () => {
    return MyRequest.get({
      url: '/member/order/pre'
    })
  }

  repurchaseOrder = (orderId) => {
    return MyRequest.get({
      url: '/member/order/repurchase/' + orderId
    })
  }

  addAddress = (form) => {
    return MyRequest.post({
      url: '/member/address',
      data: form
    })
  }

  editAddress = (form) => {
    return MyRequest.put({
      url: `/member/address/${form.id}`,
      data: form
    })
  }

  submitOrder = (data) => {
    return MyRequest.post({
      url: '/member/order',
      data
    })
  }

  findOrderDetail = (orderId) => {
    return MyRequest.get({
      url: '/member/order/' + orderId
    })
  }
  /**
   * 获取订单列表
   * @param {String} page - 页码
   * @param {String} pageSize - 每页条数
   * @param {String} orderState - 订单状态，1为待付款、2为待发货、3为待收货、4为待评价、5为已完成、6为已取消，未传该参数或0为全部
   * @returns
   */
  findOrderList = ({ page = 1, pageSize = 10, orderState = 0 }) => {
    return MyRequest.get({
      url: '/member/order',
      params: { page, pageSize, orderState }
    })
  }

  cancelOrder = ({ orderId, cancelReason }) => {
    return MyRequest.put({
      url: `/member/order/${orderId}/cancel`,
      data: { cancelReason }
    })
  }

  deleteOrder = (orderId) => {
    return MyRequest.delete({
      url: '/member/order',
      data: { ids: [orderId] }
    })
  }

  confirmOrder = (orderId) => {
    return MyRequest.put({
      url: `/member/order/${orderId}/receipt`
    })
  }

  logisticsOrder = (orderId) => {
    return MyRequest.get({
      url: `/member/order/${orderId}/logistics`
    })
  }
}

export default new Order()
